﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
using KPIS.GERP.Models.Class;
using KPIS.GERP.Models.HRM;

namespace KPIS.GERP.Models.SYS
{
    [Table("sys_sc_users"), DataContract]
    public class User
    {
        public User()
        {
            RecordStatus = "U";
        }

        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [DataMember, Display(Name = "UserId", ResourceType = typeof(Resources.UserResource))]
        [Column("user_seq")]
        public int UserId { get; set; }

        [DataMember, Display(Name = "EmpId", ResourceType = typeof(Resources.UserResource))]
        [ForeignKey("Employee")]
        [Column("emp_seq")]
        public int? EmpId { get; set; }

        [CustomRequired]
        [DataMember, Display(Name = "Code", ResourceType = typeof(Resources.UserResource))]
        [Column("user_code")]
        public string Code { get; set; }

        [DataType(DataType.Password)]
        [DataMember, Display(Name = "Password", ResourceType = typeof(Resources.UserResource))]
        [Column("user_password")]
        public string Password { get; set; }

        [DataMember]
        [Column("user_first_name")]
        public string UserFirstName { get; set; }

        [DataMember]
        [Column("user_last_name")]
        public string UserLastName { get; set; }

        [ForeignKey("JobSite")]
        [DataMember]
        [Column("user_job_site_seq")]
        public int? JobSiteId { get; set; }

        [ForeignKey("Position")]
        [DataMember]
        [Column("user_pos_seq")]
        public int? PosId { get; set; }

        [DataMember]
        [Column("is_admin")]
        public bool IsAdmin { get; set; }

        [DataMember]
        [Column("user_citizen")]
        public string Citizen { get; set; }

        [DataMember]
        [Column("user_status")]
        public string Status { get; set; }

        [DataMember]
        public virtual Employee Employee { get; set; }

        [DataMember]
        public virtual HRM.JobSite JobSite { get; set; }

        [DataMember]
        public virtual Position Position { get; set; }

        [NotMapped]
        public string FullName { get { return Employee != null ? Employee.FullName : string.Empty; } }

        [NotMapped]
        public string JobSiteName { get { return JobSite != null ? JobSite.Code + " - " + JobSite.Name : string.Empty; } }

        #region RecordStatus

        [EnumDataType(typeof(SYS.RecordStatus.EnumRecordStatus))]
        [DataMember, Display(Name = "RecordStatus", ResourceType = typeof(SYS.Resources.RecordStatusResource))]
        [Column("record_status")]
        public string RecordStatus { get; set; }

        [DataMember, Display(Name = "CreatedBy", ResourceType = typeof(SYS.Resources.RecordStatusResource))]
        [Column("created_by")]
        public Nullable<int> CreatedBy { get; set; }

        [DataMember, Display(Name = "CreatedWhen", ResourceType = typeof(SYS.Resources.RecordStatusResource))]
        [Column("created_when")]
        public Nullable<System.DateTime> CreatedWhen { get; set; }

        [DataMember, Display(Name = "UpdatedBy", ResourceType = typeof(SYS.Resources.RecordStatusResource))]
        [Column("updated_by")]
        public Nullable<int> UpdatedBy { get; set; }

        [DataMember, Display(Name = "UpdatedWhen", ResourceType = typeof(SYS.Resources.RecordStatusResource))]
        [Column("updated_when")]
        public Nullable<System.DateTime> UpdatedWhen { get; set; }

        #endregion

    }
}
